home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / STRTOL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  515 b   |  21 lines

  1. /* strtol.c, from p.183 of Turbo C Bible  */
  2. /* Converts a string to a long integer. */
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. main(int argc, char **argv)
  6. {
  7.     char *stop_at;                 /* Marks where strtol stopped      */
  8.     int  radix;
  9.     long value;
  10.     if(argc < 3)
  11.     {
  12.         printf("Usage: %s <value> <radix>\n", argv[0]);
  13.     }
  14.     else
  15.     {
  16.         radix = atoi(argv[2]);
  17.         value = strtol(argv[1], &stop_at, radix);
  18.         printf("Value read in radix %d = %ld\n"
  19.             "Stopped at: %s\n", radix, value, stop_at);
  20.     }
  21. }